﻿using System;
using System.Collections.Generic;
using Silent.API.LastFm.EventArgs;
using Silent.API.LastFm.Model;
using Silent.API.LastFm.Requests;

namespace Silent.API.LastFm
{
    public class LastFmApi
    {
        private string ApiKey { get; set; }
        private string Secret { get; set; }

        #region Events

        public event EventHandler<DataEventArgs<Album>> AlbumInfoCompleted;
        protected virtual void OnAlbumInfoCompleted(DataEventArgs<Album> e)
        {
            EventHandler<DataEventArgs<Album>> handler = this.AlbumInfoCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        public event EventHandler<AlbumsDataEventArgs> AlbumSearchCompleted;
        protected virtual void OnAlbumSearchCompleted(AlbumsDataEventArgs e)
        {
            EventHandler<AlbumsDataEventArgs> handler = this.AlbumSearchCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        public event EventHandler<DataEventArgs<Artist>> ArtistInfoCompleted;
        protected virtual void OnArtistInfoCompleted(DataEventArgs<Artist> e)
        {
            EventHandler<DataEventArgs<Artist>> handler = this.ArtistInfoCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        public event EventHandler<ArtistDataEventArgs> ArtistSearchCompleted;
        protected virtual void OnArtistSearchCompleted(ArtistDataEventArgs e)
        {
            EventHandler<ArtistDataEventArgs> handler = this.ArtistSearchCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        public event EventHandler<DataEventArgs<Track>> TrackInfoCompleted;
        protected virtual void OnTrackInfoCompleted(DataEventArgs<Track> e)
        {
            EventHandler<DataEventArgs<Track>> handler = TrackInfoCompleted;
            if (handler != null) handler(this, e);
        }
        public event EventHandler<TracksDataEventArgs> TrackSearchCompleted;
        protected virtual void OnTrackSearchCompleted(TracksDataEventArgs e)
        {
            EventHandler<TracksDataEventArgs> handler = TrackSearchCompleted;
            if (handler != null) handler(this, e);
        }
        public event EventHandler<DataEventArgs<string>> AuthentificationTokenCompleted;
        protected virtual void OnAuthentificationTokenCompleted(DataEventArgs<string> e)
        {
            EventHandler<DataEventArgs<string>> handler = this.AuthentificationTokenCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        public event EventHandler<DataEventArgs<Session>> AuthentificationSessionCompleted;
        protected virtual void OnAuthentificationSessionCompleted(DataEventArgs<Session> e)
        {
            EventHandler<DataEventArgs<Session>> handler = this.AuthentificationSessionCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        public LastFmApi(string apiKey, string secret)
        {
            ApiKey = apiKey;
            Secret = secret;
        }

        #region Album

        public Album GetAlbumInfo(string artist, string album)
        {
            var objects = new AlbumInfoRequest(ApiKey, artist, album).Request();
            OnAlbumInfoCompleted(new DataEventArgs<Album>(objects));
            return objects;
        }
        public List<Album> GetAlbumSearch(string album)
        {
            var objects = new AlbumSearchRequest(ApiKey, album).Request();
            OnAlbumSearchCompleted(new AlbumsDataEventArgs(objects));
            return objects;
        }
        public List<Album> GetAlbumSearch(string artist, string album)
        {
            var objects = new AlbumSearchRequest(ApiKey, artist, album).Request();
            OnAlbumSearchCompleted(new AlbumsDataEventArgs(objects));
            return objects;
        }

        #endregion

        #region Artist

        public Artist GetArtistInfo(string artist)
        {
            var objects = new ArtistInfoRequest(ApiKey, artist).Request();
            OnArtistInfoCompleted(new DataEventArgs<Artist>(objects));
            return objects;
        }
        public List<Artist> GetArtistSearch(string artist)
        {
            var objects = new ArtistSearchRequest(ApiKey, artist).Request();
            OnArtistSearchCompleted(new ArtistDataEventArgs(objects));
            return objects;
        }

        #endregion

        #region Auth

        public string GetToken()
        {
            var token = new AuthentificationTokenRequest(ApiKey).Request();
            OnAuthentificationTokenCompleted(new DataEventArgs<string>(token));
            return token;
        }
        public Session GetSession(string token, bool needAuthorization)
        {
            var session = new AuthnetificationSessionRequest(ApiKey, token, Secret, needAuthorization).Request();
            OnAuthentificationSessionCompleted(new DataEventArgs<Session>(session));
            return session;
        }

        #endregion

        #region Chart



        #endregion

        #region Event



        #endregion

        #region Geo



        #endregion

        #region Group



        #endregion

        #region Library



        #endregion

        #region Playlist



        #endregion

        #region Radio



        #endregion

        #region Tag



        #endregion

        #region Tasteometer




        #endregion

        #region Track

        public Track GetTrackInfo(string artist, string track)
        {
            var objects = new TrackInfoRequest(ApiKey, artist, track).Request();
            OnTrackInfoCompleted(new DataEventArgs<Track>(objects));
            return objects;
        }
        public List<Track> GetTrackSearch(string track)
        {
            var objects = new TrackSearchRequest(ApiKey, track).Request();
            OnTrackSearchCompleted(new TracksDataEventArgs(objects));
            return objects;
        }
        public List<Track> GetTrackSearch(string artist, string track)
        {
            var objects = new TrackSearchRequest(ApiKey, artist, track).Request();
            OnTrackSearchCompleted(new TracksDataEventArgs(objects));
            return objects;
        }

        #endregion

        #region User



        #endregion

        #region Venue



        #endregion
    }
}
